<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="/css/common.css" rel="stylesheet" type="text/css" />
<style>
.wrapContent {margin:0 auto;padding:0 30px;}
.center {text-align:center;}
.block {padding:10px 30px;}
.line {border:none;border-bottom:1px solid #666;clear:both;}
.orderSN {float:left;}
.orderMan {float:right;margin:-6px 20px 0 0;}
ul.machineType{width:80%;}
ul.machineType li{float:left;width:33%;line-height:26px;height:26px;}
.lineHeight{height:34px;line-height:34px;}
.right {text-align:right;width:120px;vertical-align:top}
.errMsg {color:red;margin:0 0 0 5px;}
.topBorder {border-top:1px solid #000;}
.rightBorder {border-right:1px solid #000;}
</style>
</head>
<body>
<div class="wrapContent">
	<div class="block">
		<?php 
			if ($from == 'shipped') {
				$status = '已发订单';
			}else {
				if ($orderInfo['status']==0) {
					$status = '待发订单';
				}else if ($orderInfo['status']==1) {
					$status = '部分发货订单';
				}else if ($orderInfo['status']==2) {
					$status = '已发订单';
				}
			}
		?>
		<h2 class="center">订单详情(<?php echo $status; ?>)</h2>
		<span class="orderSN">订单号：<?php echo $orderInfo['sn']; ?></span>
		<span class="orderMan">下单人：<?php echo $orderInfo['person_name']; ?></span>
	</div>
	<div class="line"></div>
	<div class="block">
		<table style="width:100%;border:none;" cellpadding="0" cellspacing="0">
			<tr class="lineHeight">
				<td class="right">用户信息：</td>
				<td><?php echo $orderInfo['customer_name']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">地区：</td>
				<td><?php echo str_replace('_', '', $orderInfo['customer_area']); ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">详细地址：</td>
				<td><?php echo $orderInfo['customer_address']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">邮政编码：</td>
				<td><?php echo $orderInfo['customer_zipcode']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">联系人：</td>
				<td><?php echo $orderInfo['customer_contact']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">电话：</td>
				<td><?php echo $orderInfo['customer_tel']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">Email：</td>
				<td><?php echo $orderInfo['customer_email']; ?></td>
			</tr>
		</table>
	</div>
	<div class="line"></div>
	<div class="block">
		<table style="width:100%;border:none;" cellpadding="0" cellspacing="0">
			<tr class="lineHeight">
				<td class="right">机器名称：</td>
				<td><?php echo $orderInfo['machine_name'];?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">机器型号：</td>
				<td><?php echo $orderInfo['machine_type']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">机器序号：</td>
				<td><?php echo $orderInfo['machine_sn']; ?></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">耗材型号：</td>
				<td>
					<table id="cartridgesInfo" cellpadding="0" cellspacing="0" style="width:80%;text-align:center;border:1px solid #000;">
						<tr>
							<td width="60%" class="rightBorder">硒鼓型号</td>
							<td width="40%">个数</td>
						</tr>
						<?php 
						$cartridgesInfo = explode(',', $orderInfo['cartridges_info']);
						foreach($cartridgesInfo as $cartridgeInfo) {
							echo '<tr>';
							list($type, $count) = explode('_', $cartridgeInfo);
							echo '<td width="60%" class="topBorder rightBorder">'.$type.'</td>';
							echo '<td width="40%" class="topBorder ">'.$count.'</td>';
							echo '</tr>';
						}
						?>
					</table>
				</td>
			</tr>
		</table>
	</div>
	
	<div class="line"></div>
	<?php 
	if ($userInfo['level']>1000) {
	//修改 发货时间等 和 修改订单 和 标记发货
	?>
		<div class="block">
			<table style="width:100%;border:none;" cellpadding="0" cellspacing="0">
				<tr class="lineHeight">
					<td class="right">发货时间：</td>
					<td>
						<?php if (!$orderInfo['status']) { ?>
						<input id="shippedTime" style="width:200px;" value="<?php echo date('Y-m-d H:i:s'); ?>"/><b id="shippedTimeErrMsg" class="errMsg">*</b>
						<?php }else { echo $orderInfo['shipped_time']; }?>
					</td>
				</tr>
				<tr class="lineHeight">
					<td class="right">快递公司：</td>
					<td>
						<?php if (!$orderInfo['status']) { ?>
						<select id="expressNameSelect">
						<?php
							echo "<option value='-1'>请选择</option>";
							foreach($expressList as $expressInfo){
								echo "<option value='{$expressInfo['tel']}'>{$expressInfo['name']}</option>";
							}
						?>
						</select>
						<b id="expressNameErrMsg" class="errMsg">*</b>
						<?php }else { echo $orderInfo['express_name']; }?>
					</td>
				</tr>
				<tr class="lineHeight">
					<td class="right">快递公司电话：</td>
					<td>
						<?php if (!$orderInfo['status']) { ?>
						<input id="expressTel" style="width:200px;" /><b id="expressTelErrMsg" class="errMsg"></b>
						<?php }else { echo $orderInfo['express_tel']; }?>
					</td>
				</tr>
				<tr class="lineHeight">
					<td class="right">快递号：</td>
					<td>
						<?php if (!$orderInfo['status']) { ?>
						<input id="expressID" style="width:200px;" /><b id="expressIDErrMsg" class="errMsg">*</b>
						<?php }else { echo $orderInfo['express_id']; }?>
					</td>
				</tr>
				<tr class="lineHeight">
					<td class="right">备注：</td>
					<td>
						<div><?php echo $orderInfo['remark']; ?></div>
						<textarea id="remark" cols="40" rows="5"></textarea>
					</td>
				</tr>
				<?php if ($userInfo['level'] > 1000 && $from!='shipped') { ?>
				<tr class="lineHeight">
					<td class="right">发货状态：</td>
					<td>
						<?php if ($orderInfo['status'] == 2) { echo '全部发货'; } else {
							//未发订单时，默认全选
							if (!$orderInfo['status']) {
								$shippedStatus = 2;
							}else {
								$shippedStatus = (int)$orderInfo['status'];
							}
							?>
							<input id="shipped_all" type="radio" name="shipped_status" value="1" <?php if ($shippedStatus==2){echo 'checked';} ?>><label for="shipped_all">全部发货</label>
							<input id="shipped_part" type="radio" name="shipped_status" value="0" <?php if ($shippedStatus==1){echo 'checked';} ?>><label for="shipped_part">部分发货</label>
						<?php } ?>
					</td>
				</tr>
				<tr class="lineHeight">
					<td class="right">发货信息：</td>
					<td>
						<?php if ($orderInfo['status'] < 2) { ?>
						<textarea id="shipped_remark" cols="40" rows="5" <?php if ($shippedStatus==2){echo "disabled";} ?>><?php echo $orderInfo['shipped_remark']; ?></textarea>
						<?php }else { echo $orderInfo['shipped_remark']; }?>
					</td>
				</tr>
				<?php } ?>
			</table>
		</div>
		<div class="line"></div>
		<?php if ($orderInfo['status'] < 2 && $from != 'shipped') { ?>
		<div class="center">
			<?php if (!$orderInfo['status']) { ?>
			<input id="delOrder" type="button" class="submitBtn" value="删除订单"/>
			<input id="modifyOrder" type="button" class="submitBtn" value="修改订单"/>
			<?php } ?>
			<input id="submit" type="button" class="submitBtn" value="标记发货"/>
		</div>
		<?php }else { ?>
			<div class="center">
			<input id="addNewRemark" type="button" class="submitBtn" value="提交新备注"/>
		</div>
		<?php }
	}else if ($userInfo['level']>100){ //查看 发货时间等 和 修改订单?>
		<div class="block">
			<table style="width:100%;border:none;" cellpadding="0" cellspacing="0">
				<tr class="lineHeight">
					<td class="right">发货时间：</td>
					<td><?php if ($orderInfo['status']) {echo $orderInfo['shipped_time']; } ?></td>
				</tr>
				<tr class="lineHeight">
					<td class="right">快递号：</td>
					<td><?php if ($orderInfo['status']) {echo $orderInfo['express_id']; } ?></td>
				</tr>
				<tr class="lineHeight">
					<td class="right">备注：</td>
					<td>
						<div><?php echo $orderInfo['remark']; ?></div>
						<textarea id="remark" cols="40" rows="5"></textarea>
					</td>
				</tr>
			</table>
		</div>
		<div class="line"></div>
		<?php if (!$orderInfo['status']) { ?>
		<div class="center">
			<input id="delOrder" type="button" class="submitBtn" value="删除订单"/>
			<input id="modifyOrder" type="button" class="submitBtn" value="修改订单"/>
		</div>
		<?php }else { ?>
			<div class="center">
			<input id="addNewRemark" type="button" class="submitBtn" value="提交新备注"/>
		</div>
		<?php }
	} ?>
</div>
</body>
<script src="/js/lib.min.js" type="text/javascript"></script>
<script type="text/javascript">
var remarkInput = $('#remark');
var orderID = <?php echo $orderInfo['id']; ?>;
$('#modifyOrder').attr({onclick:function(){
	location.href = '/admin/order.php?op=modify&id='+orderID;
}});
<?php if ($userInfo['level'] > 100) { ?>
var delOrderBtn = $('#delOrder');
delOrderBtn.attr({onclick:function(){
	delOrderBtn.val('正在处理，请稍后...');
	delOrderBtn[0].disabled = true;
	$.ajax({
		url:'/admin/order.php?op=doDel',
		data:{'id':orderID},
		type:'POST',
		callback:function(res){
			alert(res.errmsg);
			location.href = '/admin/order.php?op=queryPending';
		}
	});
}});
<?php } ?>
<?php if ($userInfo['level'] > 1000) { ?>
function getRadioValue(name){
	var val = 0,
		radios = document.getElementsByName(name);
	for (i=0;i<radios.length;i++){
		if (radios[i].checked){
			val = radios[i].value;
		}
	}
	return parseInt(val);
}
function getSelectValue(id) {
	var obj = $('#'+id)[0];
	return obj.options[obj.selectedIndex].value;
}
function getSelectText(id) {
	var obj = $('#'+id)[0];
	return obj.options[obj.selectedIndex].text;
}
var shippedTimeInput = $('#shippedTime'),
	shippedTimeErrMsg = $('#shippedTimeErrMsg'),
	expressNameSelect = $('#expressNameSelect'),
	expressNameErrMsg = $('#expressNameErrMsg'),
	expressTelInput = $('#expressTel'),
	expressTelErrMsg = $('#expressTelErrMsg'),
	expressIDInput = $('#expressID'),
	expressIDErrMsg = $('#expressIDErrMsg'),
	shippedAllRidao = $('#shipped_all'),
	shippedPartRidao = $('#shipped_part'),
	shippedRemarkInput = $('#shipped_remark'),
	submitBtn = $('#submit');

shippedAllRidao.attr({onclick:function(e){
	shippedRemarkInput[0].disabled = true;
}});
shippedPartRidao.attr({onclick:function(e){
	shippedRemarkInput[0].disabled = false;
}});

expressNameSelect.attr({onchange:function(){
	var tel = getSelectValue('expressNameSelect');
	if (tel=='-1') {
		expressTelInput.val('');
		return ;
	}
	
	expressTelInput.val(tel);
}});

var orderStatus = <?php echo $orderInfo['status']; ?>;

function submitUnFinishedOrder() {
	submitBtn.val('正在处理，请稍后...');
	submitBtn[0].disabled = true;
	
	$.ajax({
		url:'/admin/order.php?op=signShippedForUnFinished',
		data:{'id':orderID, 'shipped_status':getRadioValue('shipped_status'), 'shipped_remark':$.trim(shippedRemarkInput.val()), 'remark':$.trim(remarkInput.val())},
		type:'POST',
		callback:function(res){
			alert(res.errmsg);
			submitBtn.val('标记发货');
			submitBtn[0].disabled = false;
			if (res.errno == '0') {
				location.href = '/admin/order.php?op=queryUnFinished';
			}
		}	
	});
}
submitBtn.attr({onclick:function(){
	
	if (orderStatus == 1) {
		submitUnFinishedOrder();
		return ;
	}
	
	var checkFlag = true;
	var shippedTime = $.trim(shippedTimeInput.val());
	if (!shippedTime) {
		shippedTimeErrMsg.html('请填写发货时间');
		checkFlag && shippedTimeInput[0].focus();
		checkFlag = false;
	}else {
		shippedTimeErrMsg.html('*');
	}
	
	var expressNameValue = getSelectValue('expressNameSelect');
	if (expressNameValue=='-1') {
		expressNameErrMsg.html('请选择快递公司');
		checkFlag && expressNameSelect[0].focus();
		checkFlag = false;
	}else {
		expressNameErrMsg.html('*');
	}
	
	var expressTel = $.trim(expressTelInput.val());
	var expressID = $.trim(expressIDInput.val());
	if (!expressID) {
		expressIDErrMsg.html('请填写快递号');
		checkFlag && expressIDInput[0].focus();
		checkFlag = false;
	}else {
		expressIDErrMsg.html('*');
	}

	if (!checkFlag) {
		return ;
	}
	
	submitBtn.val('正在处理，请稍后...');
	submitBtn[0].disabled = true;
	
	$.ajax({
		url:'/admin/order.php?op=signShipped',
		data:{'id':orderID, 'shipped_time':shippedTime, 'express_name':$.trim(getSelectText('expressNameSelect')), 'express_tel':expressTel, 'express_id':expressID, 'remark':$.trim(remarkInput.val()), 'shipped_status':getRadioValue('shipped_status'), 'shipped_remark':$.trim(shippedRemarkInput.val())},
		type:'POST',
		callback:function(res){
			alert(res.errmsg);
			submitBtn.val('标记发货');
			submitBtn[0].disabled = true;
			shippedTimeInput[0].disabled = true;
			expressIDInput[0].disabled = true;
			remarkInput[0].disabled = true;
			$('#modifyOrder')[0].disabled = true;
			$('#submit')[0].disabled = true;
			if (res.errno == '0') {
				location.href = '/admin/order.php?op=queryPending';
			}
		}	
	});
}});
//设置input是否可编辑
if (shippedRemarkInput.length > 0) {
	shippedRemarkInput[0].disabled = !!getRadioValue('shipped_status');
}
<?php } ?>

<?php if ($orderInfo['status'] == 2 || $from == 'shipped') { ?>
var addNewRemarkBtn = $('#addNewRemark');
addNewRemarkBtn.attr({onclick:function(){
	
	if (!$.trim(remarkInput.val())) {
		alert('请输入备注内容');
		return ;
	}
	
	addNewRemarkBtn.val('正在处理，请稍后...');
	addNewRemarkBtn[0].disabled = true;
	
	$.ajax({
		url:'/admin/order.php?op=doAddNewRemark',
		data:{'id':orderID, 'remark':$.trim(remarkInput.val())},
		type:'POST',
		callback:function(res){
			alert(res.errmsg);
			remarkInput[0].disabled = false;
			addNewRemarkBtn[0].disabled = false;
			if (res.errno == '0') {
				location.reload();
			}
		}	
	});
	remarkInput[0].disabled = true;
}});
<?php } ?>
</script>
</html>